home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / Kibitz / SaveBoardImage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  2.8 KB  |  138 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        saveboardimage.c
  5. ** Writtem by:  Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __ERRORS__
  21. #include <Errors.h>
  22. #endif
  23.  
  24. #ifndef __UTILITIES__
  25. #include <Utilities.h>
  26. #endif
  27.  
  28.  
  29.  
  30. /*****************************************************************************/
  31.  
  32.  
  33. #ifdef powerc
  34. #pragma options align=mac68k
  35. #endif
  36. typedef struct TMDHdr {
  37.     OSType    fType;
  38.     short    hdrID;
  39.     short    version;
  40.     short    prRec[60];
  41.     Fixed    xOrigin;
  42.     Fixed    yOrigin;
  43.     Point    xScale;
  44.     Point    yScale;
  45.     short    atrState[31];
  46.     short    lCnt;
  47.     short    lTot;
  48.     long    lSiz;
  49.     Rect    lR2D;
  50.     short    filler1[145];
  51. } TMDhdr;
  52. #ifdef powerc
  53. #pragma options align=reset
  54. #endif
  55.  
  56. static TMDhdr    boardHeader = {
  57.     'PICT',
  58.     0x0000        /* NOT MacDraw II specific data.  Just simple PICT. */
  59. };
  60.  
  61. extern short    gPrintPage;
  62.  
  63.  
  64.  
  65. /*****************************************************************************/
  66. /*****************************************************************************/
  67.  
  68. #ifdef applec
  69. #pragma segment SaveBoardImage
  70. #endif
  71.  
  72. /*****************************************************************************/
  73. /*****************************************************************************/
  74.  
  75.  
  76.  
  77. OSErr    SaveBoardImage(FileRecHndl frHndl)
  78. {
  79.     StandardFileReply    reply;
  80.     FInfo                finfo;
  81.     WindowPtr            oldPort;
  82.     Rect                boardRect;
  83.     short                fileRefNum;
  84.     PicHandle            boardImage;
  85.     long                count;
  86.     OSErr                err;
  87.  
  88.     reply.sfFile.name[0] = 0;
  89.     if (!DisplayPutFile(&reply)) return(userCanceledErr);        /* User canceled the save. */
  90.  
  91.     err = Create_OpenFile(&reply.sfFile, &fileRefNum, 'PICT');
  92.     if (err) return(err);        /* Oops. */
  93.  
  94.     HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, &finfo);
  95.     finfo.fdCreator = 'ttxt';
  96.     HSetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, &finfo);
  97.  
  98.     oldPort = SetFilePort(frHndl);
  99.  
  100.     boardRect = BoardRect();
  101.     InsetRect(&boardRect, -1, -1);
  102.     boardImage = OpenPicture(&boardRect);
  103.     if (!boardImage) {
  104.         SetPort(oldPort);
  105.         return(memFullErr);
  106.     }
  107.  
  108.     ImageBoardLines(1, kBoardHOffset, kBoardVOffset);
  109.     gPrintPage = -1;
  110.     ImageDocument(frHndl, true);
  111.     gPrintPage = 0;
  112.  
  113.     ClosePicture();
  114.  
  115.     err = SetFPos(fileRefNum, fsFromStart, 0);
  116.         /* Set the file position to the beginning of the file. */
  117.  
  118.     if (!err) {
  119.         count = sizeof(TMDhdr);
  120.         err   = FSWrite(fileRefNum, &count, (Ptr)&boardHeader);
  121.     }
  122.  
  123.     if (!err) {
  124.         HLock((Handle)boardImage);
  125.         count = GetHandleSize((Handle)boardImage);
  126.         err   = FSWrite(fileRefNum, &count, (Ptr)*boardImage);
  127.     }
  128.     KillPicture(boardImage);
  129.  
  130.     FSClose(fileRefNum);
  131.     SetPort(oldPort);
  132.  
  133.     return(err);
  134. }
  135.  
  136.  
  137.  
  138.